// 动态计算区域屏幕高度
export const addWindowResizeHandler = (handler) => {
  let oldHandler = window.onresize;
  if (typeof window.onresize != "function") {
    window.onresize = handler;
  } else {
    window.onresize = function () {
      oldHandler();
      handler();
    };
  }
};

// 属性深拷贝
export const deepClone = (origin) => {
  // console.log(origin,"origin");
  if (origin === undefined) {
    return undefined;
  }

  return JSON.parse(JSON.stringify(origin));
};

// // 防抖
export const debounce = (func, delay) => {
  let timerId;

  return function () {
    const context = this;
    const args = arguments;

    clearTimeout(timerId);

    timerId = setTimeout(function () {
      func.apply(context, args);
    }, delay);
  };
};

// 节流
export function throttle(func, delay) {
  let lastExecTime = 0;

  return function () {
    const context = this;
    const args = arguments;
    const currentTime = Date.now();

    if (currentTime - lastExecTime > delay) {
      func.apply(context, args);
      lastExecTime = currentTime;
    }
  };
}

